package com.lukk.TEST;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.junit.Test;

import com.lukk.util.AESUtils;
import com.lukk.util.MD5Utils;

/**
 * 
 * @author zhaochaojie
 *
 */
public class InitialSql {
	DBHelp db = new DBHelp();

	// 初始化员工密码
	@Test
	public void test1() throws Exception {
		updateLukk_internalWorker(1, "zhaochaojie456987", "lukkzhaochaojie");
		updateLukk_internalWorker(2, "wangfanfan456987", "lukkwangfanfan");
		updateLukk_internalWorker(3, "zhangrui456987", "lukkzhangrui");
		updateLukk_internalWorker(4, "sunxuekui456987", "lukksunxuekui");
		updateLukk_internalWorker(5, "chuzeguo456987", "lukkchuzeguo");
		updateLukk_internalWorker(6, "xulele456987", "lukkxulele");
	}

	/**
	 * @param password
	 *            密码
	 * @param workerCode
	 *            员工标识
	 * @throws Exception
	 */

	public void updateLukk_internalWorker(Integer id, String password, String workerCode) throws Exception {
		String saltCode = MD5Utils.getRandomString(8);
		System.out.println(password + " 盐值是： + " + AESUtils.aesEncrypt(saltCode, AESUtils.SALTKEY));
		System.out.println(password + " 密码是： + " + MD5Utils.GetSaltCode(password, saltCode));
		String updateSql = "INSERT INTO lukk_internalWorker (id,workerCode, password, salt, createTime) VALUES (? , ?, ?, ?, '2017-2-10');";
		Connection updateCon = db.getCon();
		PreparedStatement prepareStatement = updateCon.prepareStatement(updateSql);
		prepareStatement.setString(4, AESUtils.aesEncrypt(saltCode, AESUtils.SALTKEY));
		prepareStatement.setString(3, MD5Utils.GetSaltCode(password, saltCode));
		prepareStatement.setString(2, workerCode);
		prepareStatement.setInt(1, id);
		prepareStatement.executeUpdate();
		db.closeAll(updateCon, prepareStatement, null);
	}

}
